const mongoose = require("mongoose");
const Schema = mongoose.Schema;



const msgSchema = new Schema({ //用户表规则
    content: { //内容
        type: String,
        required: true
    },
    date: { //时间
        type: Number,
        required: true,
        default: Date.now //生产当前时间时间戳
    },
    likes: [ //点赞数，存所有点过赞的id
        { type: Schema.Types.ObjectId }
    ],
    author: { //当前发表这条评论的用户
        type: Schema.Types.ObjectId,
        ref: "user", //关联到用户表
        required: true
    },
    children: [ //回复留言（二级评论/子评论）    子文档
        {
            content: String,
            author: { type: Schema.Types.ObjectId, ref: "user" },  //这条回复是谁写的/写回复的用户id
            date: { type: Number, default: Date.now },
            likes: [{ type: Schema.Types.ObjectId }],
            replyId: { type: Schema.Types.ObjectId, ref: "user" }//这条子回复是回复的谁？ / 它的父级评论的作者id
        }
    ]

});
module.exports = mongoose.model("message", msgSchema); //导出user表的操作对象